package cn.wolfcode.qo;

import java.util.List;

/*
封装结果集（莫一页的数据）
 */
public class PageResult<T> {
    //两个用户输入的
    private int currentPage;
    private int pageSize;
    //两条sql语句执行的结果
    private int totalCount;
    private List<T> data;
    //后台计算
    private int prevPage;
    private int nextPage;
    private int totalPage;

    @Override
    public String toString() {
        return "PageResult{" +
                "currentPage=" + currentPage +
                ", pageSize=" + pageSize +
                ", totalCount=" + totalCount +
                ", data=" + data +
                ", prevPage=" + prevPage +
                ", nextPage=" + nextPage +
                ", totalPage=" + totalPage +
                '}';
    }

    public PageResult(int currentPage, int pageSize, int totalCount, List<T> data) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.totalCount = totalCount;
        this.data = data;
        this.totalPage=totalCount % pageSize == 0 ? totalCount / pageSize: totalCount / pageSize + 1;
        this.prevPage = currentPage-1>=1?currentPage-1:1;
        this.nextPage =currentPage+1<=this.totalPage?currentPage+1:this.totalPage;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    public int getPrevPage() {
        return prevPage;
    }

    public void setPrevPage(int prevPage) {
        this.prevPage = prevPage;
    }

    public int getNextPage() {
        return nextPage;
    }

    public void setNextPage(int nextPage) {
        this.nextPage = nextPage;
    }

    public int getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }
}
